<!DOCTYPE html>
<html> 
    <head> 
        <title>TU Braunschweig mobil</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width; initial-scale=1; maximum-scale=1; user-scalable=no;">
        <link rel="shortcut icon" href="themes/images/tubs_favicon.ico" type="image/ico" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
        <link rel="stylesheet" href="themes/TU-BS.css" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    </head> 

    <body> 
        <div data-role="page" id="personen">
            <div data-role="header" data-position="inline">
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                <div id="header">
                    <a href="index-mobile.php" data-ajax="false"><img src="themes/images/siegel.png" width="71px" height="74px" alt="TU Siegel"></a>
                </div>
                    </div>
                    <div class="ui-block-b">
                <div id="crumb">
                    <img src="themes/images/112-group@2xw.png" height="36px" width="48px">
                </div>
                    </div>
                </div>
            <div style="clear: both"></div>
            </div>
            <div data-role="content" data-theme="b">
                <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                        <label for="personensuche" class="ui-hidden-accessible">Personensuche:</label>
                        <input data-theme="d" type="search" name="personensuche" id="search" placeholder="Nachname">
                </form>
                <?php
                if (isset($_POST["personensuche"])) {
                    $searchstring = $_POST["personensuche"];
                }
                else
                    $searchstring = "";
                
                $ldaphost = "ldap.tu-bs.de";
                $ldapport = 389;
                $ldapconn = ldap_connect($ldaphost, $ldapport) or die("Could not connect to $ldaphost");  // LDAP Server

                if ($ldapconn) {
                    //Bindung
                    $ldapbind = ldap_bind($ldapconn);
                    if($ldapbind)
                        $j = -1;
                    else
                        $j = 0;

                    // Suchen des CN Eintrages per Nachname
                    $search = ldap_search($ldapconn, "o=TU Braunschweig, c=DE", "sn=" . $searchstring . "");
                    //Suchen des CN Eintrages per Vorname
                    //$search += ldap_search($ldapconn,"o=TU Braunschweig, c=DE", "givenname=".$searchstring."");
                    //Einträge aus dem Suchergbnis holen
                    $info = ldap_get_entries($ldapconn, $search);
                    echo "<ul data-role='listview' data-inset='true'>";
                    echo "<li>Sucheingabe: " . $searchstring . "</li>";
                    if (isset($info["count"]))
                        echo "<li data-role='list-divider'>Daten für " . $info["count"] . " Person/en gefunden:</li>";
                    else
                        echo "<li data-role='list-divider'>Daten für 0 Person/en gefunden:</li>";
                    
                    //Details Ausgeben
                    for ($i = 0; $i < $info["count"]; $i++) {
                        $j = 1;
                        echo "<li><h3>" . $info[$i]["sn"][0] . ", " . $info[$i]["givenname"][0] . "</h3>";
                        if (isset($info[$i]["mail"][0])) {
                            echo "<p>E-Mail: <a href='mailto:" . $info[$i]["mail"][0] . "'>" . $info[$i]["mail"][0] . "  <img src='themes/images/18-envelope.png'></a></p>";
                        }
                        else {
                            echo "<br><p>E-Mail: Nicht angegeben</p>";
                        }
                                                
                        if (isset($info[$i]["telephonenumber"][0])) {
                            echo "<p>Tel. Nr.: <a href='tel:" . $info[$i]["telephonenumber"][0] . "'>" . $info[$i]["telephonenumber"][0] . "  <img src='themes/images/75-phone.png'></a></p>";
                        }
                        else {
                            echo "<br><p>Tel. Nr.: Nicht angegeben</p>";
                        }
                        echo "<p>Institution/Status: " . $info[$i]["physicaldeliveryofficename"][0] . "  <img src='themes/images/190-bank.png'></p></li>";                                              
                    }

                    if($j == 0 and $ldapbind == false)
                            echo "<li><h3>Kein Zugang zum Uni Netzwerk vorhanden!</h3></li>";
                    echo "</ul>";
                    ldap_close($ldapconn);
                } else {
                    echo "<li><h3>Verbindung zum LDAP Server nicht möglich</h3></li>";
                }
                ?>
            </div>
        </div>
    </body>
</html>